package com.ruoyi.system.service.impl;

import java.util.List;
import java.util.UUID;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.SysPhotoMapper;
import com.ruoyi.system.domain.SysPhoto;
import com.ruoyi.system.service.ISysPhotoService;

/**
 * 照片Service业务层处理
 * 
 * @author ruoyi
 * @date 2023-10-30
 */
@Service
public class SysPhotoServiceImpl implements ISysPhotoService 
{
    @Autowired
    private SysPhotoMapper sysPhotoMapper;

    /**
     * 查询照片
     * 
     * @param photoKey 照片主键
     * @return 照片
     */
    @Override
    public SysPhoto selectSysPhotoByPhotoKey(String photoKey)
    {
        return sysPhotoMapper.selectSysPhotoByPhotoKey(photoKey);
    }

    /**
     * 查询照片列表
     * 
     * @param sysPhoto 照片
     * @return 照片
     */
    @Override
    public List<SysPhoto> selectSysPhotoList(SysPhoto sysPhoto)
    {
        return sysPhotoMapper.selectSysPhotoList(sysPhoto);
    }

    /**
     * 新增照片
     * 
     * @param sysPhoto 照片
     * @return 结果
     */
    @Override
    public int insertSysPhoto(SysPhoto sysPhoto)
    {
        sysPhoto.setPhotoKey(UUID.randomUUID().toString());
        LoginUser loginUser = (LoginUser) SecurityUtils.getAuthentication().getPrincipal();
        Long userId = loginUser.getUser().getUserId();
        sysPhoto.setCreateBy(userId.toString());
        sysPhoto.setCreateTime(DateUtils.getNowDate());
        return sysPhotoMapper.insertSysPhoto(sysPhoto);
    }

    /**
     * 修改照片
     * 
     * @param sysPhoto 照片
     * @return 结果
     */
    @Override
    public int updateSysPhoto(SysPhoto sysPhoto)
    {
        LoginUser loginUser = (LoginUser) SecurityUtils.getAuthentication().getPrincipal();
        Long userId = loginUser.getUser().getUserId();
        sysPhoto.setUpdateBy(userId.toString());
        sysPhoto.setUpdateTime(DateUtils.getNowDate());
        return sysPhotoMapper.updateSysPhoto(sysPhoto);
    }

    /**
     * 批量删除照片
     * 
     * @param photoKeys 需要删除的照片主键
     * @return 结果
     */
    @Override
    public int deleteSysPhotoByPhotoKeys(String[] photoKeys)
    {
        return sysPhotoMapper.deleteSysPhotoByPhotoKeys(photoKeys);
    }

    /**
     * 删除照片信息
     * 
     * @param photoKey 照片主键
     * @return 结果
     */
    @Override
    public int deleteSysPhotoByPhotoKey(String photoKey)
    {
        return sysPhotoMapper.deleteSysPhotoByPhotoKey(photoKey);
    }

    @Override
    public List<SysPhoto> selectSysPhotoByWorksKey(String worksKey) {
        return sysPhotoMapper.selectSysPhotoByWorksKey(worksKey);
    }

    @Override
    public List<SysPhoto> selectPhotoByWorksKey(String worksKey) {
        return sysPhotoMapper.selectPhotoByWorksKey(worksKey);
    }

}
